<template>
  <div id="uesrtext">
    <textarea placeholder="按 Ctrl + Enter 发送" v-model="content" v-on:keyup="addMessage"></textarea>
  </div>
</template>

<script>

import {mapState} from 'vuex'
const currentUser = JSON.parse(localStorage.getItem('userInfo'))

export default {
  name: 'uesrtext',
  data () {
    return {
      content:''
    }
  },

  methods: {
  	addMessage (e) {
      console.log('545454545',this.$store.state.chat.currentSessionId)
  		if (e.ctrlKey && e.keyCode ===13 && this.content.length) {
        console.log('cu',currentUser)
        let userInfo = currentUser
        let msgObj = new Object()
        msgObj.from = userInfo.managerName
        msgObj.nickName = userInfo.managerName
        msgObj.to = this.$store.state.chat.currentSessionId.managerName;
        msgObj.content = this.content
        this.$store.state.chat.stompClient.publish({
            destination: '/app/chat', // 对应后端 @MessageMapping 路径
            body: JSON.stringify(msgObj),
        });

  			this.$store.commit('chat/addMessage',msgObj);
  			this.content='';
  		}
  	}
  }
}
</script>

<style lang="less" scoped>
#uesrtext {
	position: absolute;
  bottom: 0;
  right: 0;
  width: 100%;
  height: 30%;
  border-top: solid 1px #DDD;
  > textarea {
  	padding: 10px;
  	width: 100%;
  	height: 100%;
  	border: none;
  	outline: none;
  }
}
</style>
